/*
 * ========================================================
 * Copyright(c) 2014 杭州偶尔科技-版权所有
 * ========================================================
 * 本软件由杭州偶尔科技所有, 未经书面许可, 任何单位和个人不得以
 * 任何形式复制代码的部分或全部, 并以任何形式传播。
 * 公司网址
 * 
 * 			http://www.kkkd.com/
 * 
 * ========================================================
 */
package com.simon.mengkou.ui.activity;

import android.os.Bundle;

import com.ouertech.android.agm.lib.base.future.core.AgnettyFuture;
import com.ouertech.android.agm.lib.base.future.core.AgnettyResult;
import com.ouertech.android.agm.lib.ui.base.defaults.activity.BaseTopActivity;
import com.simon.mengkou.R;
import com.simon.mengkou.data.bean.base.Express;
import com.simon.mengkou.future.base.OuerFutureListener;
import com.simon.mengkou.system.constant.CstOuer;
import com.simon.mengkou.system.global.OuerApplication;

import butterknife.ButterKnife;

/**
 * @author : Zhenshui.Xia
 * @since : 2016/4/13.
 * desc    : 物流信息
 */
public class ExpressActivity extends BaseTopActivity{
    //订单id
    private String mOrderId;

    @Override
    protected void init(Bundle savedInstanceState) {
        super.init(savedInstanceState);
        mOrderId = getIntent().getStringExtra(CstOuer.KEY.ID);
    }

    @Override
    protected void initTop() {
        setTitle(R.string.express_title);
        setNavigation(R.drawable.common_ic_left_nav);
    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_express);
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);

        setOnRetryListener(new OnRetryListener() {
            @Override
            public void onRetry() {
                expressInfo();
            }
        });

        expressInfo();
    }

    /**
     * 获取物流信息
     */
    private void expressInfo() {
        AgnettyFuture future = OuerApplication.mOuerFuture.expressInfo(mOrderId,
                new OuerFutureListener(this) {
                    @Override
                    public void onStart(AgnettyResult result) {
                        super.onStart(result);
                        setLoading(true);
                    }

                    @Override
                    public void onComplete(AgnettyResult result) {
                        super.onComplete(result);
                        setLoading(false);
//                        Express express = (Express) result.getAttach();
                        Express express = new Express();
                        express.setId(mOrderId);
                        express.setExpressId("111");
                        express.setExpressName("顺丰快递");
                    }

                    @Override
                    public void onException(AgnettyResult result) {
                        super.onException(result);
                        setRetry(true);
                    }

                    @Override
                    public void onNetUnavaiable(AgnettyResult result) {
                        super.onNetUnavaiable(result);
                        setRetry(true);
                    }
                });

        attachDestroyFutures(future);
    }
}
